package oaSystem.biz.impl;

import java.util.List;
import java.util.Map;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import oaSystem.biz.EmployeeBiz;
import oaSystem.entity.Employee;
import oaSystem.entity.Function;
import oaSystem.entity.Role;

public class Test {
	public static void main(String[] args) {

		EmployeeBiz imp = new ClassPathXmlApplicationContext("spring-beans.xml").getBean(EmployeeBiz.class);
		
		
		Employee checkLogin = imp.checkLogin("Nr023", "123");
		List<Role> roles = checkLogin.getRoles();
		for (Role role : roles) {
			Map<String, List<Function>> functions = role.getFunctions();
	/*		List<Function> list = functions.get("menuItem");
			for (Function function : list) {
				if(function.getParentId()==null){
					System.out.println(function.getName());
				}
				for (Function fu : function.getChildren()) {
					System.out.println("\t"+fu.getName());
					if(fu.getChildren()!=null){
						for (Function fu2 : fu.getChildren()) {
							System.out.println("\t\t"+fu2.getName());
						}
					}
				}
			}*/
			
			List<Function> pageList = functions.get("menuItem");
			for (Function function : pageList) {
				if(function.getParentId()==null){
					System.out.println(function.getName());
				}
				getChileItem(function,true);
			}
			
			System.out.println("--------------------------------------------");
			
			pageList = functions.get("pageMenuItem");
			for (Function function : pageList) {
				if(function.getParentId()==null){
					System.out.println(function.getName());
				}
				getChileItem(function,false);
			}
		}
	}
	private static void getChileItem(Function function,boolean isMenuItem) {
		if(isMenuItem){//页面菜单栏
			for (Function fu : function.getChildren()) {
				System.out.println("\t"+fu.getName());
				getChileItem(fu,isMenuItem);
			}
		}else{//具体页面菜单
			for (Function fu : function.getPageChildren()) {
				System.out.println("\t"+fu.getName());
				getChileItem(fu,isMenuItem);
			}
		}
		
	}

	
}
